const path = require('path')
const {defineConfig,build} = require('vite')
const vue = require('@vitejs/plugin-vue')
const vueJsx = require('@vitejs/plugin-vue-jsx')


//打包入口文件夹
const entryDir = path.resolve(__dirname,'../packages')
//出口文件加
const outDir = path.resolve(__dirname,'../lib')

//vite配置
const baseConfig = defineConfig({
    configFile:false,
    publicDir:false,
    plugins:[vue(),vueJsx()]
})

//rollup
const rollupOptions={
    external: ['vue','vue-router'],
    output:{
        global:{
            vue:'Vue'
        }
    }
}

//全量构建
const buildAll = async ()=>{
    await build({
        ...baseConfig,
        build:{
            rollupOptions,
            lib:{
                entry:path.resolve(entryDir,'index.ts'),
                name:'my-element-component',
                fileName:'my-element-component',
                formats:['es','umd']
            },
            outDir

        }
    })
}


const buildLib = async ()=>{
    await buildAll()
}

buildLib()
